﻿import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Templates 2.15 as T

/*
设备连接设定界面
*/

Popup {
    // id:backGround
    id:connectPopUp
    width: screenWidth * 0.6
    height: screenHeight * 0.95
    background:     Rectangle{
        // anchors.fill: backGround
        color: "pink"
    }
    closePolicy: Popup.NoAutoClose

    Item{
        id:backGround
        anchors.fill: parent
    }

    Text{
        anchors.horizontalCenter: backGround.horizontalCenter
        anchors.top: backGround.top
        anchors.topMargin: backGround.height * 0.01
        font.pixelSize: 60
        color:"red"
        text:qsTr("连接参数")
    }

    Rectangle{
        anchors.horizontalCenter: backGround.horizontalCenter
        anchors.top: backGround.top
        anchors.topMargin: 110
        width: backGround.width
        height: 1
        color: "black"
    }

    Text{
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 130
        font.pixelSize: 30
        font.bold: true
        text:qsTr("PLC-串口号:")
    }

    ComboBox{       // PLC - 串口号选择框
        id:serialPort_PLC
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 170
        width: 400
        height: 40
        model:Cpp_Connect.serialInfo

        contentItem: Text {     //界面上显示出来的文字
            leftPadding: 20      //左部填充为5
            text: serialPort_PLC.displayText   //表示ComboBox上显示的文本
            font: serialPort_PLC.font          //文字大小
            color: serialPort_PLC.enabled ? "black" : "grey"   //serialPort_PLC.pressed ?
            verticalAlignment: Text.AlignVCenter        //文字位置
        }

        background: Rectangle {   //背景项
            implicitWidth: 120
            implicitHeight: 40
            property string sColor: serialPort_PLC.enabled ? "white" : "lightgrey"
            color: serialPort_PLC.pressed ? Qt.darker(sColor, 1.2) : sColor
            border.width: 1
            border.color: "lightgrey"
            radius: 0
        }

        onPressedChanged: {
            if(pressed === true)
            {
                Cpp_Connect.scanAvailabelInfo();
            }
        }

    }


    Text{
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 220
        font.pixelSize: 30
        font.bold: true
        text:qsTr("PLC-波特率:")
    }

    ComboBox{       // PLC - 波特率选择框
        id: baudRate_PLC
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 260
        width: 400
        height: 40
        model:["9600","19200","38400","57600","115200"]
        currentIndex: 4

        contentItem: Text {     //界面上显示出来的文字
            leftPadding: 20      //左部填充为5
            text: baudRate_PLC.displayText   //表示ComboBox上显示的文本
            font: baudRate_PLC.font          //文字大小
            color: baudRate_PLC.enabled ? "black" : "grey"   //baudRate_PLC.pressed ?
            verticalAlignment: Text.AlignVCenter        //文字位置
        }

        background: Rectangle {   //背景项
            implicitWidth: 120
            implicitHeight: 40
            property string sColor: baudRate_PLC.enabled ? "white" : "lightgrey"
            color: baudRate_PLC.pressed ? Qt.darker(sColor, 1.2) : sColor
            border.width: 1
            border.color: "lightgrey"
            radius: 0
        }

    }

    Text{
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 310
        font.pixelSize: 30
        font.bold: true
        text:qsTr("PLC-数据位:")
    }

    ComboBox{       // PLC - 数据位选择框
        id: dataBit_PLC
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 350
        width: 400
        height: 40
        model:["5","6","7","8"]
        currentIndex: 3

        contentItem: Text {     //界面上显示出来的文字
            leftPadding: 20      //左部填充为5
            text: dataBit_PLC.displayText   //表示ComboBox上显示的文本
            font: dataBit_PLC.font          //文字大小
            color: dataBit_PLC.enabled ? "black" : "grey"   //dataBit_PLC.pressed ?
            verticalAlignment: Text.AlignVCenter        //文字位置
        }

        background: Rectangle {   //背景项
            implicitWidth: 120
            implicitHeight: 40
            property string sColor: dataBit_PLC.enabled ? "white" : "lightgrey"
            color: dataBit_PLC.pressed ? Qt.darker(sColor, 1.2) : sColor
            border.width: 1
            border.color: "lightgrey"
            radius: 0
        }

    }

    Text{
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 400
        font.pixelSize: 30
        font.bold: true
        text:qsTr("PLC-校验位:")
    }

    ComboBox{       // PLC - 校验位选择框
        id: parityBit_PLC
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 440
        width: 400
        height: 40
        model:["None","Even","Odd","Mark","Space"]
        currentIndex: 0

        contentItem: Text {     //界面上显示出来的文字
            leftPadding: 20      //左部填充为5
            text: parityBit_PLC.displayText   //表示ComboBox上显示的文本
            font: parityBit_PLC.font          //文字大小
            color: parityBit_PLC.enabled ? "black" : "grey"   //parityBit_PLC.pressed ?
            verticalAlignment: Text.AlignVCenter        //文字位置
        }

        background: Rectangle {   //背景项
            implicitWidth: 120
            implicitHeight: 40
            property string sColor: parityBit_PLC.enabled ? "white" : "lightgrey"
            color: parityBit_PLC.pressed ? Qt.darker(sColor, 1.2) : sColor
            border.width: 1
            border.color: "lightgrey"
            radius: 0
        }

    }

    Text{
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 490
        font.pixelSize: 30
        font.bold: true
        text:qsTr("PLC-停止位:")
    }

    ComboBox{       // PLC - 停止位选择框
        id: stopBit_PLC
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 530
        width: 400
        height: 40
        model:["1","1.5","2"]
        currentIndex: 0

        contentItem: Text {     //界面上显示出来的文字
            leftPadding: 20      //左部填充为5
            text: stopBit_PLC.displayText   //表示ComboBox上显示的文本
            font: stopBit_PLC.font          //文字大小
            color: stopBit_PLC.enabled ? "black" : "grey"   //stopBit_PLC.pressed ?
            verticalAlignment: Text.AlignVCenter        //文字位置
        }

        background: Rectangle {   //背景项
            implicitWidth: 120
            implicitHeight: 40
            property string sColor: stopBit_PLC.enabled ? "white" : "lightgrey"
            color: stopBit_PLC.pressed ? Qt.darker(sColor, 1.2) : sColor
            border.width: 1
            border.color: "lightgrey"
            radius: 0
        }

    }



    Rectangle{
        anchors.horizontalCenter: backGround.horizontalCenter
        anchors.top: backGround.top
        anchors.topMargin: 610
        width: backGround.width
        height: 1
        color: "black"
    }


    Text{
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 640
        font.pixelSize: 30
        font.bold: true
        text:qsTr("打印机-串口号:")
    }

    ComboBox{       // 打印机 - 串口号选择框
        id:serialPort_Printer
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 680
        width: 400
        height: 40
        model:Cpp_Connect.serialInfo

        contentItem: Text {     //界面上显示出来的文字
            leftPadding: 20      //左部填充为5
            text: serialPort_Printer.displayText   //表示ComboBox上显示的文本
            font: serialPort_Printer.font          //文字大小
            color: serialPort_Printer.enabled ? "black" : "grey"   //serialPort_Printer.pressed ?
            verticalAlignment: Text.AlignVCenter        //文字位置
        }

        background: Rectangle {   //背景项
            implicitWidth: 120
            implicitHeight: 40
            property string sColor: serialPort_Printer.enabled ? "white" : "lightgrey"
            color: serialPort_Printer.pressed ? Qt.darker(sColor, 1.2) : sColor
            border.width: 1
            border.color: "lightgrey"
            radius: 0
        }

        onPressedChanged: {
            if(pressed === true)
            {
                Cpp_Connect.scanAvailabelInfo();
            }
        }
    }

    Text{
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 730
        font.pixelSize: 30
        font.bold: true
        text:qsTr("打印机-波特率:")
    }

    ComboBox{       // 打印机 - 波特率选择框
        id:baudRate_Printer
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 770
        width: 400
        height: 40
        model:["9600","19200","38400","57600","115200"]
        currentIndex: 0

        contentItem: Text {     //界面上显示出来的文字
            leftPadding: 20      //左部填充为5
            text: baudRate_Printer.displayText   //表示ComboBox上显示的文本
            font: baudRate_Printer.font          //文字大小
            color: baudRate_Printer.enabled ? "black" : "grey"   //baudRate_Printer.pressed ?
            verticalAlignment: Text.AlignVCenter        //文字位置
        }

        background: Rectangle {   //背景项
            implicitWidth: 120
            implicitHeight: 40
            property string sColor: baudRate_Printer.enabled ? "white" : "lightgrey"
            color: baudRate_Printer.pressed ? Qt.darker(sColor, 1.2) : sColor
            border.width: 1
            border.color: "lightgrey"
            radius: 0
        }
    }

    Text{
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 820
        font.pixelSize: 30
        font.bold: true
        text:qsTr("打印机-数据位:")
    }

    ComboBox{       // 打印机 - 数据位选择框
        id:dataBit_Printer
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 860
        width: 400
        height: 40
        model:[5,6,7,8]
        currentIndex:3

        contentItem: Text {     //界面上显示出来的文字
            leftPadding: 20      //左部填充为5
            text: dataBit_Printer.displayText   //表示ComboBox上显示的文本
            font: dataBit_Printer.font          //文字大小
            color: dataBit_Printer.enabled ? "black" : "grey"   //dataBite_Printer.pressed ?
            verticalAlignment: Text.AlignVCenter        //文字位置
        }

        background: Rectangle {   //背景项
            implicitWidth: 120
            implicitHeight: 40
            property string sColor: dataBit_Printer.enabled ? "white" : "lightgrey"
            color: dataBit_Printer.pressed ? Qt.darker(sColor, 1.2) : sColor
            border.width: 1
            border.color: "lightgrey"
            radius: 0
        }
    }

    Text{
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 910
        font.pixelSize: 30
        font.bold: true
        text:qsTr("打印机-校验位:")
    }

    ComboBox{       // 打印机 - 校验位选择框
        id: parityBit_Printer
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 950
        width: 400
        height: 40
        model:["None","Even","Odd"]
        currentIndex: 0

        contentItem: Text {     //界面上显示出来的文字
            leftPadding: 20      //左部填充为5
            text: parityBit_Printer.displayText   //表示ComboBox上显示的文本
            font: parityBit_Printer.font          //文字大小
            color: parityBit_Printer.enabled ? "black" : "grey"   //parityBit_Printer.pressed ?
            verticalAlignment: Text.AlignVCenter        //文字位置
        }

        background: Rectangle {   //背景项
            implicitWidth: 120
            implicitHeight: 40
            property string sColor: parityBit_Printer.enabled ? "white" : "lightgrey"
            color: parityBit_Printer.pressed ? Qt.darker(sColor, 1.2) : sColor
            border.width: 1
            border.color: "lightgrey"
            radius: 0
        }
    }

    Text{
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 1000
        font.pixelSize: 30
        font.bold: true
        text:qsTr("打印机-停止位:")
    }

    ComboBox{       // 打印机 - 停止位选择框
        id:stopBit_Printer
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 1040
        width: 400
        height: 40
        model:["1","1.5","2"]
        currentIndex: 0

        contentItem: Text {     //界面上显示出来的文字
            leftPadding: 20      //左部填充为5
            text: stopBit_Printer.displayText   //表示ComboBox上显示的文本
            font: stopBit_Printer.font          //文字大小
            color: stopBit_Printer.enabled ? "black" : "grey"   //stopBit_Printer.pressed ?
            verticalAlignment: Text.AlignVCenter        //文字位置
        }

        background: Rectangle {   //背景项
            implicitWidth: 120
            implicitHeight: 40
            property string sColor: stopBit_Printer.enabled ? "white" : "lightgrey"
            color: stopBit_Printer.pressed ? Qt.darker(sColor, 1.2) : sColor
            border.width: 1
            border.color: "lightgrey"
            radius: 0
        }
    }

    Rectangle{
        anchors.horizontalCenter: backGround.horizontalCenter
        anchors.top: backGround.top
        anchors.topMargin: 1120
        width: backGround.width
        height: 1
        color: "black"
    }

    Text{
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 1160
        font.pixelSize: 30
        font.bold: true
        text:qsTr("扫码枪-串口号:")
    }

    ComboBox{       // 扫码枪 - 串口号选择框
        id:serialPort_Scanner
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 1200
        width: 400
        height: 40
        model:Cpp_Connect.serialInfo
        // currentIndex: 0

        contentItem: Text {     //界面上显示出来的文字
            leftPadding: 20      //左部填充为5
            text: serialPort_Scanner.displayText   //表示ComboBox上显示的文本
            font: serialPort_Scanner.font          //文字大小
            color: serialPort_Scanner.enabled ? "black" : "grey"   //serialPort_Scanner.pressed ?
            verticalAlignment: Text.AlignVCenter        //文字位置
        }

        background: Rectangle {   //背景项
            implicitWidth: 120
            implicitHeight: 40
            property string sColor: serialPort_Scanner.enabled ? "white" : "lightgrey"
            color: serialPort_Scanner.pressed ? Qt.darker(sColor, 1.2) : sColor
            border.width: 1
            border.color: "lightgrey"
            radius: 0
        }

        onPressedChanged: {
            if(pressed === true)
            {
                Cpp_Connect.scanAvailabelInfo();
            }
        }
    }

    Text{
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 1250
        font.pixelSize: 30
        font.bold: true
        text:qsTr("扫码枪-波特率:")
    }

    ComboBox{       // 扫码枪 - 波特率选择框
        id:baudRate_Scanner
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 1290
        width: 400
        height: 40
        model:["9600","19200","38400","57600","115200"]
        currentIndex: 0

        contentItem: Text {     //界面上显示出来的文字
            leftPadding: 20      //左部填充为5
            text: baudRate_Scanner.displayText   //表示ComboBox上显示的文本
            font: baudRate_Scanner.font          //文字大小
            color: baudRate_Scanner.enabled ? "black" : "grey"   //baudRate_Scanner.pressed ?
            verticalAlignment: Text.AlignVCenter        //文字位置
        }

        background: Rectangle {   //背景项
            implicitWidth: 120
            implicitHeight: 40
            property string sColor: baudRate_Scanner.enabled ? "white" : "lightgrey"
            color: baudRate_Scanner.pressed ? Qt.darker(sColor, 1.2) : sColor
            border.width: 1
            border.color: "lightgrey"
            radius: 0
        }
    }

    Text{
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 1340
        font.pixelSize: 30
        font.bold: true
        text:qsTr("扫码枪-数据位:")
    }

    ComboBox{       // 扫码枪 - 数据位选择框
        id:dataBit_Scanner
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 1380
        width: 400
        height: 40
        model:[5,6,7,8]
        currentIndex: 3

        contentItem: Text {     //界面上显示出来的文字
            leftPadding: 20      //左部填充为5
            text: dataBit_Scanner.displayText   //表示ComboBox上显示的文本
            font: dataBit_Scanner.font          //文字大小
            color: dataBit_Scanner.enabled ? "black" : "grey"   //dataBit_Scanner.pressed ?
            verticalAlignment: Text.AlignVCenter        //文字位置
        }

        background: Rectangle {   //背景项
            implicitWidth: 120
            implicitHeight: 40
            property string sColor: dataBit_Scanner.enabled ? "white" : "lightgrey"
            color: dataBit_Scanner.pressed ? Qt.darker(sColor, 1.2) : sColor
            border.width: 1
            border.color: "lightgrey"
            radius: 0
        }
    }

    Text{
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 1430
        font.pixelSize: 30
        font.bold: true
        text:qsTr("打印机-校验位:")
    }

    ComboBox{       // 扫码枪 - 校验位选择框
        id:parityBit_Scanner
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 1470
        width: 400
        height: 40
        model:["None","Even","Odd"]
        currentIndex: 0

        contentItem: Text {     //界面上显示出来的文字
            leftPadding: 20      //左部填充为5
            text: parityBit_Scanner.displayText   //表示ComboBox上显示的文本
            font: parityBit_Scanner.font          //文字大小
            color: parityBit_Scanner.enabled ? "black" : "grey"   //parityBit_Scanner.pressed ?
            verticalAlignment: Text.AlignVCenter        //文字位置
        }

        background: Rectangle {   //背景项
            implicitWidth: 120
            implicitHeight: 40
            property string sColor: parityBit_Scanner.enabled ? "white" : "lightgrey"
            color: parityBit_Scanner.pressed ? Qt.darker(sColor, 1.2) : sColor
            border.width: 1
            border.color: "lightgrey"
            radius: 0
        }
    }

    Text{
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 1520
        font.pixelSize: 30
        font.bold: true
        text:qsTr("扫码枪-停止位:")
    }

    ComboBox{       // 扫码枪 - 停止位选择框
        id:stopBit_Scanner
        anchors.left: backGround.left
        anchors.leftMargin: 90
        anchors.top: backGround.top
        anchors.topMargin: 1560
        width: 400
        height: 40
        model:["1","1.5","2"]
        currentIndex: 0

        contentItem: Text {     //界面上显示出来的文字
            leftPadding: 20      //左部填充为5
            text: stopBit_Scanner.displayText   //表示ComboBox上显示的文本
            font: stopBit_Scanner.font          //文字大小
            color: stopBit_Scanner.enabled ? "black" : "grey"   //stopBit_Scanner.pressed ?
            verticalAlignment: Text.AlignVCenter        //文字位置
        }

        background: Rectangle {   //背景项
            implicitWidth: 120
            implicitHeight: 40
            property string sColor: stopBit_Scanner.enabled ? "white" : "lightgrey"
            color: stopBit_Scanner.pressed ? Qt.darker(sColor, 1.2) : sColor
            border.width: 1
            border.color: "lightgrey"
            radius: 0
        }
    }

    Rectangle{
        anchors.horizontalCenter: backGround.horizontalCenter
        anchors.top: backGround.top
        anchors.topMargin: 1630
        width: backGround.width
        height: 1
        color: "black"
    }

    Rectangle{
        anchors.left: backGround.left
        anchors.leftMargin: 30
        anchors.bottom: backGround.bottom
        anchors.bottomMargin: 40
        width: 200
        height: 100
        radius: 10
        color: "#006cee"
        border.width:  1
        border.color: "#f0f8ff"

        Text {
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            text: qsTr("连 接")
        }

        MouseArea{
            anchors.fill : parent

            onPressed: {
                parent.color = "#ff3606"
            }

            onReleased: {
                parent.color = "#006cee"

                Cpp_Connect.saveChoosedSerialMessage(serialPort_PLC.currentText,
                                                     baudRate_PLC.currentText,
                                                     dataBit_PLC.currentText,
                                                     parityBit_PLC.currentText,
                                                     stopBit_PLC.currentText,
                                                     serialPort_Printer.currentText,
                                                     baudRate_Printer.currentText,
                                                     dataBit_Printer.currentText,
                                                     parityBit_Printer.currentText,
                                                     stopBit_Printer.currentText,
                                                     serialPort_Scanner.currentText,
                                                     baudRate_Scanner.currentText,
                                                     dataBit_Scanner.currentText,
                                                     parityBit_Scanner.currentText,
                                                     stopBit_Scanner.currentText)
                Cpp_Connect.connectMechines();
            }
        }
    }

    Rectangle{
        anchors.right: backGround.right
        anchors.rightMargin: 30
        anchors.bottom: backGround.bottom
        anchors.bottomMargin: 40
        width: 200
        height: 100
        radius: 10
        color: "#006cee"
        border.width:  1
        border.color: "#f0f8ff"

        Text {
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            text: qsTr("退 出")
        }

        MouseArea{
            anchors.fill : parent

            onPressed: {
                parent.color = "#ff3606"
            }

            onReleased: {
                parent.color = "#006cee"
                connectSettingWindow.close()
            }
        }
    }

}
